/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * IncidenciesEAulesAppCli.java
 *
 * Created on 07-nov-2011, 22:14:35
 */
package edu.uoc.tdp.pac3.client.gui;

import edu.uoc.tdp.pac3.client.gui.panels.inicial.PanelInicial;
import edu.uoc.tdp.pac3.client.gui.panels.alta.PanelAlta;
import edu.uoc.tdp.pac3.client.gui.panels.consulta.PanelConsulta;
import edu.uoc.tdp.pac3.client.gui.panels.resolucio.PanelResolucio;
import edu.uoc.tdp.pac3.rmi.GestorIncidenciesInterface;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.awt.FlowLayout;
import java.awt.BorderLayout;
import java.rmi.Naming;



/**
 *
 * @author Alex
 */
public class Client extends javax.swing.JFrame {

    private PanelInicial panelInicial;
    private PanelAlta panelAlta;
    private PanelResolucio panelResolucio;
    private PanelConsulta panelConsulta;
    
    private GestorIncidenciesInterface bo;
    private String urlRMI = "rmi://localhost:2020/rmiServer";
    
    
    
    
    /** Creates new form IncidenciesEAulesAppCli */
    public Client() {
        //super("Operaciones Básicas");
        initComponents();
        this.setLayout(new FlowLayout());

        DesactivaPanels();
        panelInicial = new PanelInicial();
        this.add(panelInicial, BorderLayout.CENTER);
        this.pack();
        
        try {
            bo = (GestorIncidenciesInterface) Naming.lookup(urlRMI);
        } catch (NotBoundException ex) {
            Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
        } catch (MalformedURLException ex) {
            Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
        } catch (RemoteException ex) {
            Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("ESPAIS - Aplicatiu Client - UOC Tardor 2011");
        getContentPane().setLayout(null);

        jMenuBar1.setName("jMenuBar1"); // NOI18N

        jMenu1.setText("Inici");
        jMenu1.setName("jMenu1"); // NOI18N
        jMenu1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jMenu1MouseClicked(evt);
            }
        });
        jMenu1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jInicialActionPerformed(evt);
            }
        });
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Gestor d'Incidències");
        jMenu2.setName("jMenu2"); // NOI18N
        jMenu2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jMenu2MouseClicked(evt);
            }
        });

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext().getActionMap(Client.class, this);
        jMenuItem1.setAction(actionMap.get("ActionAlta")); // NOI18N
        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setText("Alta nova incidència");
        jMenuItem1.setName("jMenuItem1"); // NOI18N
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jaltaActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem1);

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem2.setText("Apunt o resolució d'incidència");
        jMenuItem2.setName("jMenuItem2"); // NOI18N
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jresoActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem2);

        jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem3.setText("Consulta d'històric");
        jMenuItem3.setName("jMenuItem3"); // NOI18N
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jconsActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem3);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jMenu1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenu1MouseClicked
// TODO add your handling code here:
    //if (panelInicial.isShowing()==false) MostraPanelInicial();
    DesactivaPanels();
    panelInicial = new PanelInicial();
    this.add(panelInicial, BorderLayout.CENTER);
    this.pack();
}//GEN-LAST:event_jMenu1MouseClicked

private void jMenu2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenu2MouseClicked
// TODO add your handling code here:

}//GEN-LAST:event_jMenu2MouseClicked

private void jaltaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jaltaActionPerformed
    DesactivaPanels();
    panelAlta = new PanelAlta(bo);
    this.add(panelAlta, BorderLayout.CENTER);
    this.pack();
}//GEN-LAST:event_jaltaActionPerformed

private void jresoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jresoActionPerformed
    DesactivaPanels();
    panelResolucio = new PanelResolucio(bo);
    this.add(panelResolucio, BorderLayout.CENTER);
    this.pack();
}//GEN-LAST:event_jresoActionPerformed

private void jconsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jconsActionPerformed
    DesactivaPanels();
    panelConsulta = new PanelConsulta(bo);
    this.add(panelConsulta, BorderLayout.CENTER);
    this.pack();
}//GEN-LAST:event_jconsActionPerformed

private void jInicialActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jInicialActionPerformed
// TODO add your handling code here:
    DesactivaPanels();
    panelInicial = new PanelInicial();
    this.add(panelInicial, BorderLayout.CENTER);
    this.pack();
}//GEN-LAST:event_jInicialActionPerformed



private void DesactivaPanels(){
    try{
        this.remove(panelInicial);
        }
        catch(Exception e){
        }
    try{
        this.remove(panelAlta);
        }
        catch(Exception e){
        }
    try{
        this.remove(panelResolucio);
        }
        catch(Exception e){
        }
    try{
        this.remove(panelConsulta);
        }
        catch(Exception e){
        }
}

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Client.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Client.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Client.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Client.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Client().setVisible(true);
            }
        });
    }

//        IncidenciesEAulesAppCli.getOwnerlessWindows().

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    // End of variables declaration//GEN-END:variables
}
